<template>
  <div>
    <div class="banner">
      <div class="imgs">
        <van-swipe class="my-swipe" :autoplay="3000" indicator-color="white">
          <van-swipe-item v-for="(item, index) in banners" :key="index">
            <img :src="item.pic" alt="" />
          </van-swipe-item>
        </van-swipe>
      </div>
    </div>
    <div class="remLists">
      <div class="title">推荐</div>
      <div class="content">
        <van-row gutter="5">
          <van-col
            class="li"
            span="8"
            v-for="(item, index) in personalized"
            :key="index"
            @click="goMusiclist(item.id)"
          >
            <img :src="item.picUrl" alt="" />
            <span class="remd_lnum">{{ item.playCount | playCountA }}</span>
            <p>{{ item.name }}</p>
          </van-col>
        </van-row>
      </div>
    </div>

    <div class="newsong">
      <dl>
        <dt>最新音乐</dt>
        <dd v-for="(item,index) in recommendsongs" :key="index" @click="playmusic(index,item.id, item.name, item.ar)">
          <div class="info">
            <h2>{{item.name}}</h2>
            <h3><span  v-for="(key,i) in item.ar" :key="i">{{key.name}}&nbsp;</span></h3>
          </div>
          <div class="bf">
          <span class="iconfont icon-bofang"></span>
        </div>
        </dd>
      </dl>
    </div>

    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
  </div>
</template>


<script>
import { getBanner, getPersonalized,getSongs} from "../api/recommend";
export default {
  data() {
    return {
      banners: "",
      personalized: "",
      recommendsongs:""
    };
  },
  methods: {
    getBannerFun() {
      // 请求数据
      getBanner().then((data) => {
        if (data.code == 200) {
          this.banners = data.banners;
        }
        console.log(data);
      });
    },
    getPersonalizedFun() {
      // 请求数据
      getPersonalized({ limit: 9 }).then((data) => {
        console.log(data);

        this.personalized = data.result;
      });
    },
    goMusiclist(id) {
      console.log(id);
      this.$router.push({
        path: "/recommend/musiclist",
        query: { id },
      });
    },
    getSongsFun(){
        getSongs().then((data)=>{
            if(data.code == 200){
                console.log(data);
                console.log(data.data.dailySongs);
                this.recommendsongs = data.data.dailySongs
                console.log(this.recommendsongs);
            }
        })
    },
    playmusic(index,id, name, ar) {
      let playMusicData = {
        coverImgUrl: this.recommendsongs[index].al.picUrl,
        id,
        name,
        ar,
        tracks: this.recommendsongs,
      };
      // 数据存存储
      // this.resetSetItem.save(playMusicData);
      this.$store.commit("musicDatafun",playMusicData)
      let musciclists  = JSON.parse(JSON.stringify(playMusicData))
      this.$store.commit("musicListfun",musciclists)
    },
    
  },
  created() {
    this.getBannerFun();
    this.getPersonalizedFun();
    this.getSongsFun();
  },
  filters: {
    playCountA(value) {
      let w = value > 10000 ? value / 10000 : value; // 万计算
      let y = w > 10000 ? parseInt(w / 10000) + "亿" : parseInt(w) + "万"; //亿计算
      return y;
    },
  },
};
</script>


<style lang="less" >
.banner {
  height: 228px;
  background-color: #60c5f1;
  width: 100%;
  position: relative;
  // margin-bottom: 55px;
  .imgs {
    min-height: 228px;
    position: absolute;
    left: 0px;
    right: 0px;
    top: 0px;
    margin: auto;
    width: 96%;
    // background-color: #2CBCEE;
    border-radius: 5px;
    img {
      width: 100%;
    }
  }
}
.remLists {
  .title {
    font-size: 0.34375rem;
    height: 100px;
    line-height: 100px;
    font-weight: bold;
    text-indent: 0.5em;
  }
  .content .li {
    width: 33.33%;
    float: left;
    position: relative;
    margin-bottom: 16px;
    img {
      display: block;
      width: 100%;
      height: 200px;
      margin: 0 auto;
      border-radius: 3px;
    }
    p {
      font-size: 0.28125rem;
      color: #2f3035;
      height: 0.78125rem;
      overflow: hidden;
      line-height: 0.4375rem;
      padding: 0.15625rem 0.109375rem;
      display: -webkit-box;
      -webkit-line-clamp: 2;
      -webkit-box-orient: vertical;
    }
    .remd_lnum {
      position: absolute;
      top: 0px;
      right: 20px;
      font-size: 0.234375rem;
      color: #fff;
    }
  }
}

.newsong {
  dt {
    position: relative;
    padding-left: 9px;
    margin-bottom: 14px;
    font-size: 17px;
    height: 20px;
    line-height: 20px;
    &::after {
      content: " ";
      position: absolute;
      left: 0;
      top: 50%;
      margin-top: -9px;
      width: 2px;
      height: 16px;
      background-color: #60c5f1;
    }
  }
  dd {
    display: flex;
    padding-left: 10px;
    height: 55px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    margin: 0;
    }
    .info {
      flex: 1;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      padding-top: 10px;
      h2 {
        // height: 29px;
        font-size: 17px;
        color: #3a3c3c;
        font-weight: normal;
        overflow: hidden;
        white-space: nowrap;
        text-overflow: ellipsis;
        span{
            color: #888;
            margin-left: 4px;
            font-size: 17px;
        }
      }
      h3 {
        font-size: 12px;
        color: #888;
        font-weight: normal;
      }
    }
    .bf {
      position: absolute;
      right: 20px;
      margin-top: 10px;
      span {
        display: block;
        font-size: 15px;
        width: 22px;
        height: 22px;
        line-height: 22px;
        text-align: center;
        border: 4px solid #646565;
        color: #646565;
        border-radius: 50%;
      }
    }
  }
</style>